package org.agora.photogallery.client.view;

import java.util.List;


import org.agora.photogallery.client.model.Gallery;


import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class GalleryViewImpl extends Composite implements GalleryView{

	
	private final GalleryViewWidget collapsable1 = new GalleryViewWidget();
	private final FlowPanel contentPanel;
	private List<Gallery> galleries;
	private GalleryPresenter presenter;
	
	@Inject
	public GalleryViewImpl() {
		contentPanel = new FlowPanel();
		collapsable1.setContent(contentPanel);
		
		 initWidget(collapsable1);
	}
	
	@Override
	public void setPresenter(GalleryPresenter p ){
		presenter = p;
	}
	
	@Override
	public void setData(List<Gallery> g){
		galleries = g;
		contentPanel.clear();
		for(final Gallery gallery : galleries){
			Image image = new Image();
			image.setStyleName("galleryImage");
			image.setUrl(gallery.getThumbNailUrl());
			image.addClickHandler(new ClickHandler(){
				@Override
				public void onClick(ClickEvent event) {
					event.getSource();
					presenter.onItemClicked(gallery);
				}
				
			});			
			contentPanel.add(image);
		}
		collapsable1.setDimention();
		
//		show();
		
	}

	@Override
	public Widget asWidget() {
		return this;
	}	
	
	public void show(){
		collapsable1.show();
	}
	@Override
	public void hide(){
		collapsable1.collapse();
	}
}
